import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;

public class java07 {
    public static void main(String[] args) throws Exception {
        if (isFileEmpty("manu.txt")) {
            BufferedReader fis2 = new BufferedReader(new FileReader("names.txt"));
            ArrayList<String> arr1 = new ArrayList<>();
            String len2;
            while ((len2 = fis2.readLine())!= null) {
                arr1.add(len2);
            }
            for (int i = 0; i < 10; i++) {
                Random random = new Random();
                int n = random.nextInt(arr1.size());
                BufferedWriter fos2 = new BufferedWriter(new FileWriter("manu.txt",true));
                fos2.write(arr1.get(n));
                fos2.newLine();
                fos2.close();
            }
            fis2.close();
        } else { 
            BufferedReader fis = new BufferedReader(new FileReader("manu.txt"));
            ArrayList<String> arr = new ArrayList<>();
            String len;
            while ((len = fis.readLine())!= null) {
                arr.add(len);
            }
            Random random = new Random();
            int ran = random.nextInt(arr.size());
            System.out.println(arr.get(ran));
            arr.remove(ran);
            BufferedWriter fos = new BufferedWriter(new FileWriter("manu.txt"));
            for (int i = 0; i < arr.size(); i++) {
                fos.write(arr.get(i));
                fos.newLine();
            }
            fos.close();
            fis.close();
        }
    }

    public static boolean isFileEmpty(String filePath) {
        try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
            return reader.readLine() == null;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
}